<template>
  <div>
    <el-table class="partition" border :data="manageData" style="width: 100%">
      <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
      <el-table-column prop="name" label="编号"> </el-table-column>
      <el-table-column prop="date" label="添加时间"> </el-table-column>
      <el-table-column prop="money" label="租金"> </el-table-column>
      <el-table-column prop="typeName" label="类型"> </el-table-column>
      <el-table-column prop="date" label="车辆状态">
        <template slot-scope="scope">
          <div v-if="scope.row.state">正常</div>
          <div v-else>报废</div>
        </template>
      </el-table-column>
      <el-table-column align="center" fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" @click="updateEdit(scope.row)" size="small">修改</el-button>
          <el-button @click="deleteMange(scope.row._id)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <scrapNumber @updateSuccess="getManage" :bike_id="rowData._id" :name="rowData.name" :money="rowData.money" :type_id="rowData.type_id" :state="rowData.state" @closeDialog="handleAddChapter" v-if="isEdit"></scrapNumber>
  </div>
</template>
<script>
import { getBike, deleteBike } from "../../api/bike";
import scrapNumber from './commponent/scrapNumber'
export default {
  name: "typeCreate",
  components: {
    scrapNumber
  },
  data () {
    return {
      isEdit: false,
      rowData: {},
      manageData: [],
    };
  },
  methods: {
    // 提交登录
    getManage () {
      this.isEdit = false
      getBike().then((res) => {
        if (res.success) {
          this.manageData = res.result;
        }
      });
    },
    deleteMange (id) {
      deleteBike(id).then((res) => {
        if (res.success) {
          this.getManage();
        }
      });
    },
    updateEdit (data) {
      this.rowData = data
      this.isEdit = !this.isEdit
    },
    handleAddChapter () {
      this.isEdit = false
    },
  },
  mounted () {
    this.getManage();
  },

};
</script>
<style scoped></style>
